//
//  ViewController.m
//  UIPageControl
//
//  Created by OnePiece on 15/9/9.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
{
    UIScrollView * scroll;
    UIPageControl * pageCon;
    NSInteger idex;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view, typically from a nib.
    
    
    //scroll屏幕大小(满屏)
    scroll = [[UIScrollView alloc]initWithFrame:self.view.frame];
    
    //排列图片
    for (int i = 0; i < 3; i++)
    {
        // 先把图片添加到 image （一般就是这样添加图片的）
        UIImage * image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i]];
        
        //视图  屏幕的宽
        CGFloat flo1 = [UIScreen mainScreen].bounds.size.width;
        //试图  屏幕的高
        CGFloat flo2 = [UIScreen mainScreen].bounds.size.height;
        
        //3个imageView的坐标  并排排列
        UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i*flo1, 0, flo1, flo2)];
        
        //把 image 地址给 imageV（视图）
        imageV.image = image;
        
        //把 试图 添加到 相框
        [scroll addSubview:imageV];
        
    }
    
    //设置滚动（添加的 视图的占得总范围）的范围
    scroll.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width*3, scroll.frame.size.height);
    
    //是否弹回
    scroll.bounces = NO;
    
    //滚动时 的边框是否保存
    scroll.showsHorizontalScrollIndicator = NO;
    scroll.showsVerticalScrollIndicator = NO;
    
    //是否分页 默认不分页
    scroll.pagingEnabled = YES;
    
    // scroll要用代理时 必添加
    scroll.delegate = self;
    
    //下面 表示的小图标
    
    //建立小图标
    pageCon = [[UIPageControl alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-40 ,[UIScreen mainScreen].bounds.size.width , 40)];
    
    //pageCon.backgroundColor = [UIColor grayColor];
    
    pageCon.alpha=0.4;
    
    //小图标 数目
    pageCon.numberOfPages = 3;
    
    //图标 选中的图标为 idex = 0
    idex = 0;//从第一个
    pageCon.currentPage = idex;//从第一个
    
    //pageControl未选中的点得颜色
    pageCon.pageIndicatorTintColor = [UIColor greenColor];
    
    //pageControl当前的点得颜色
    pageCon.currentPageIndicatorTintColor = [UIColor redColor];
    pageCon.userInteractionEnabled = NO;
    
    //添加 不要错了顺序
    [self.view addSubview:scroll];
    
    [self.view addSubview:pageCon];
}

//代理  的方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    pageCon.currentPage = scrollView.contentOffset.x/[UIScreen mainScreen].bounds.size.width;
    CGSize size = [pageCon sizeForNumberOfPages:pageCon.currentPage];
    NSLog(@"%@",NSStringFromCGSize(size));
    
}





//- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
//
//    pageCon.currentPage = idex;
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
